
proc ld_run { objects ldflags dest test } {
    set ld_output [target_link $objects $dest $ldflags]
}

proc readelf_run { exec flags dest test } {
    set readelf [find_binutils_prog readelf]
    verbose -log "$readelf $flags $exec > $dest"
    catch "exec $readelf $flags $exec > $dest" readelf_output
}

proc regexp_test { file1 file2 test } {
    if [regexp_diff $file1 $file2] then { fail $test } else { pass $test }
}

global srcdir subdir
if [istarget microblaze*-*-elf] {
    foreach file [lsort [glob -nocomplain -- $srcdir/$subdir/relax_size*.s]] {
        set file [file rootname [file tail $file]]
        gas_run "$file.s" "-o $file.o" ""
        ld_run "$file.o"  "-e 0 -N -relax" "$file.x" "linking $file.x"
        readelf_run "$file.x" "-s" "$file.elf" "readelf -s $file.x"
        regexp_test "$file.elf" "$srcdir/$subdir/$file.elf" "matching $file.elf"
    }
}
